﻿#pragma once

#include "../DeviceLayer/DevicePumpBase.h"
#include "../DeviceLayer/DeviceValveBase.h"
#include "Containers.h"
#include "Service.h"
#include <thread>

namespace BusinessLayer
{

class ServiceDemoFuelFiller : public Service
{
    DECLARE_DYNAMIC_CREATE(ServiceDemoFuelFiller)

    AUTO_WIRED_DEVICE(DeviceLayer::DevicePumpBase, pump)
    AUTO_WIRED_DEVICE(DeviceLayer::DeviceValveBase, valve)

    std::thread workingThread;
    std::atomic<bool> run { false };

    void ThreadFunction();

    enum Status
    {
        idle,       //0
        starting,   //1
        started,    //2
        stopping    //3
    };

    enum Command
    {
        start,
        stop
    };

    std::atomic<Status> status { idle };
    std::atomic<Command> command { stop };

    int valveOpenThresholdRPM { 300 };
    int valveCloseThresholdRPM { 100 };

    int fillingProcess { 0 };

public:
    ServiceDemoFuelFiller();
    ~ServiceDemoFuelFiller();

    void Start() { command = start; }
    void Stop() { command = stop; }

    virtual bool InitFromSettingData(const QString& path) override;
};

}
